package com.itheima.controller;

import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// 被扫描
// 返回json
// AOP 切面
@RestControllerAdvice

public class ExceptionAdviceHandler {






    // 业务异常
    @ExceptionHandler(BusinessException.class)
    public Result business(BusinessException e) {
        e.printStackTrace();
        return new Result(Code.BUSINESS_ERR, e.getMessage(), null);
    }
    // 系统异常
    @ExceptionHandler(SystemException.class)
    public Result system(SystemException e) {
        e.printStackTrace();
        return new Result(Code.SYSTEM_ERR, e.getMessage(), null);
    }

    // 其他异常

    // 路径   拦截的异常
    // 方法

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {

        System.out.println(e.getMessage());
        return new Result(Code.ERR_ERR, "8BQ了~网络出问题了", null);
    }

}
